package com.cskaoyan.service.user;

import com.cskaoyan.mapper.MallRegionMapper;
import com.cskaoyan.model.vo.user.CityData;
import com.cskaoyan.model.vo.user.ProvinceData;
import com.cskaoyan.model.vo.user.RegionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: project-market
 * @description:
 * @author: zhijie
 * @create: 2021-12-01 11:29
 **/
@Service
public class RegionServiceImpl implements RegionService {
    @Autowired
    MallRegionMapper mallRegionMapper;

    /**
     * 1.查出所有省直辖市的集合
     * 2.查出市的集合
     * 3.查出县区的集合
     *
     * @return
     */
    @Override
    public RegionVo regionList() {
        long start = System.currentTimeMillis();
        List<ProvinceData> province = mallRegionMapper.selectProvince();
        for (ProvinceData provinceData : province) {
            provinceData.setChildren(mallRegionMapper.selectCity(provinceData.getId()));
            for (CityData child : provinceData.getChildren()) {
                child.setChildren(mallRegionMapper.selectCounty(child.getId()));
            }
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);
        RegionVo regionVo = new RegionVo();
        regionVo.setList(province);
        regionVo.setLimit(31);
        regionVo.setPage(1);
        regionVo.setPages(1);
        regionVo.setTotal(31);
        return regionVo;
    }
}
